package dao;

import model.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class AccountDaoImpl implements AccountDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public Account querryAccountByID(Integer accountId) {
        String sql = "select id, accountId, name, balance from t_account where accountId = ?";
        return jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Account.class), accountId);
    }

    @Override
    public int updateAccount(Account account) {
        String sql = "update t_account set balance = ? where accountId = ?";
        return jdbcTemplate.update(sql, account.getBalance(), account.getAccountId());
    }
}
